<!DOCTYPE html>
<html>
<head>
<include file="Include:meta" />
<title>项目款项统计-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text">项目款项统计</div>
		<div class="right">
			<div class="input-group left w200">
		    	<input type="text" id="keyword" value="{$keyword}" class="form-control" placeholder="按项目编号/名称搜索" autocomplete="off">
	    		<span class="input-group-btn">
	        		<button class="btn found_btn" type="button">搜索</button>
		    	</span>
		    </div>
		</div>
	</div>
	<div id="content">
		<div class="filter">
			<div class="filter-item">
				<div class="filter-title">所属中心：</div>
				<ul class="filter-order">
					<foreach name="pro_list" item="vo">
						<li <if condition="$center_id eq $vo['name2']">class="current"</if>>
							<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$vo['name2']}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/{$kp_type}/sk_type/{$sk_type}">{$vo['name1']}</a>
						</li>
					</foreach>
				</ul>
			</div>
			<div class="filter-item">
				<div class="filter-title">项目类型：</div>
				<ul class="filter-order">
					<li <if condition="$ptype eq -10">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/-10/start/{$start}/end/{$end}/kp_type/{$kp_type}/kp_type/{$kp_type}/sk_type/{$sk_type}">全部</a>
					</li>
					<foreach name="ptype_list" item="vo">
					<li <if condition="$ptype eq $vo['id']">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$vo['id']}/start/{$start}/end/{$end}/kp_type/{$kp_type}/kp_type/{$kp_type}/sk_type/{$sk_type}">{$vo['second_name']}</a>
					</li>
					</foreach>
				</ul>
			</div>
			<div class="filter-item">
				<div class="filter-title">开票状态：</div>
				<ul class="filter-order">
					<li <if condition="$kp_type eq -10">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/-10/sk_type/{$sk_type}">全部</a>
					</li>
					<li <if condition="$kp_type eq -1">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/-1/sk_type/{$sk_type}">未收全</a>
					</li>
					<li <if condition="$kp_type eq 1">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/1/sk_type/{$sk_type}">已收全</a>
					</li>
				</ul>
			</div>
			<div class="filter-item">
				<div class="filter-title">收款状态：</div>
				<ul class="filter-order">
					<li <if condition="$sk_type eq -10">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/{$kp_type}/sk_type/-10">全部</a>
					</li>
					<li <if condition="$sk_type eq -1">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/{$kp_type}/sk_type/-1">未收全</a>
					</li>
					<li <if condition="$sk_type eq 1">class="current"</if>>
						<a href="__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/{$kp_type}/sk_type/1">已收全</a>
					</li>
				</ul>
			</div>
			<div class="filter-item">
				<div class="filter-title">周期筛选：</div>
				<ul class="filter-order">
					<a href="{$last_url}" class="mr10">上一周期</a>
					<input name="start" value="{$start}" type="text" class="form-control Wdate required-text w100" onclick="WdatePicker()" readonly autocomplete="off">
					-
					<input name="end" value="{$end}" type="text" class="form-control Wdate required-text w100" onclick="WdatePicker()" readonly autocomplete="off">
					<button class="btn btndate ml10" type="button">搜索</button>
					<span class='error-item'>开始日期必须小于结束日期</span>
					<a href="{$next_url}" class="ml10">下一周期</a>
				</ul>
			</div>
		</div>
		<div class="table-scrollx">
			<table class="table table-bordered table-hover">
				<tr class="table-header fixed-table-header">
					<td width="">项目编号</td>
					<td width="">项目名称</td>
					<td width="">项目类型</td>
					<td width="">合同金额</td>
					<td width="">应开票金额</td>
					<td width="">应开票日期</td>
					<td width="">已开票金额</td>
					<td width="">剩余应开票金额</td>
					<td width="">已收款金额</td>
					<td width="">剩余应收款金额</td>
				</tr>
				<if condition="$result eq NULL">
				<tr>
					<td colspan="10" class="text-center">暂无相关内容</td>
				</tr>
				</if>
				<foreach name="result" item="vo">
					<tr>
						<td><a class="xm_btn" href="javascript:;" aaaid="{$vo['id']}">{$vo['project_num']}</a></td>
						<td>{$vo['project_name']}</td>
						<td>{$vo['p_typen']}</td>
						<td>{$vo['contract_money']}</td>
						<td><span data-toggle="tooltip" data-placement="right" title="" data-html="true" data-original-title="{$vo['title']}">{$vo['yinkp']}</span></td>
						<td><span data-toggle="tooltip" data-placement="right" title="" data-html="true" data-original-title="预警日期：{$vo['warn_date']} 催款日期：{$vo['press_date']}">{$vo['ticket_date']}</span></td>
						<td>
							<if condition="$vo['yikp'] eq NULL">
								<if condition="$vo['yikp_lj'] eq -1">
									<span class="red">{$vo['yikp']}</span>
								<else/>
									{$vo['yikp']}
								</if>
							<else/>
								<if condition="$vo['yikp_lj'] eq -1">
									<a class="kp_btn" href="javascript:;" bbbid="{$vo['id']}">
										<span class="red">{$vo['yikp']}</span>
									</a>
								<else/>
									<a class="kp_btn" href="javascript:;" bbbid="{$vo['id']}">{$vo['yikp']}</a>
								</if>
							</if>
						</td>
						<td>{$vo['syykp']}</td>
						<td>
							<if condition="$vo['yisk_lj'] eq -1">
								<if condition="$vo['yikp'] eq NULL">{$vo['yisk']}<else/><span class="red">{$vo['yisk']}</span></if>
							<else/>
								<if condition="$vo['yikp'] gt $vo['yisk']">
									<a class="sk_btn" href="javascript:;" cccid="{$vo['id']}" style="color:red">
										{$vo['yisk']}
									</a>
								<else/>
									<a class="sk_btn" href="javascript:;" cccid="{$vo['id']}">{$vo['yisk']}</a>
								</if>
							</if>
						</td>
						<td>{$vo['syysk']}</td>
					</tr>
				</foreach>
				<if condition="$result neq NULL">
					<tr>
						<td colspan="3">合计</td>
						<td>{$sum['contract_money']}</td>
						<td>{$sum['yinkp']}</td>
						<td></td>
						<td>{$sum['yikp']}</td>
						<td>{$sum['syykp']}</td>
						<td>{$sum['yisk']}</td>
						<td>{$sum['syysk']}</td>
					</tr>
				</if>
			</table>
		</div>
		<div class="pages">{$page}</div>
	</div>
</div>
<!--项目弹框-->
<div class="modal fade" id="xm-modal">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<div class="modal-header">
				<h4>项目款项详情</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				
			</div>
		</div>
	</div>
</div>
<!--开票弹框-->
<div class="modal fade" id="kp-modal">
	<div class="modal-dialog w1000">
		<div class="modal-content">
			<div class="modal-header">
				<h4>项目开票详情</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				
			</div>
		</div>
	</div>
</div>
<!--收款弹框-->
<div class="modal fade" id="sk-modal">
	<div class="modal-dialog w1000">
		<div class="modal-content">
			<div class="modal-header">
				<h4>项目收款详情</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body">
				
			</div>
		</div>
	</div>
</div>
<div class="toolbar-annotation">
	<div class="annotation-title">功能注解</div>
	<ul class="annotation-item">
		<li>【已开票金额标红】当前日期超过当前款项阶段的催款日期日期，并且已开票金额<应开票金额</li>
		<li>【已收款金额标红】已收款金额<已开票金额</li>
	</ul>
</div>
<include file="Include:javascript" />
<script type="text/javascript">
$(function(){
	//搜索
	$(".found_btn").keywordSearch("__APP__/Financial/project_funds_total/keyword/$keyword/center_id/{$center_id}/ptype/{$ptype}/start/{$start}/end/{$end}/kp_type/{$kp_type}/sk_type/{$sk_type}");
	
	//日期筛选
	$(".btndate").click(function(){
		var start = $("[name=start]").val(),
			end = $("[name=end]").val();
		if(Date.parse(end)>=Date.parse(start)){
			window.location.href = "__APP__/Financial/project_funds_total/keyword/{$keyword}/center_id/{$center_id}/ptype/{$ptype}/start/"+start+"/end/"+end+"/kp_type/{$kp_type}/sk_type/{$sk_type}";
		}else{
			$(this).nextAll(".error-item").show();
		}
	});
	$('.xm_btn').click(function(){
		$('#xm-modal').modal();
		var id = $(this).attr("aaaid");
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"id":id,"action":"one"},
			url:"__APP__/Financial/project_funds_total_ajax",
			success:function(data){
				var html="";
				html+= "<div class='form-main' style='border:none;margin-bottom:0'><div class='form-item'><div class='input-label'>所属中心</div><div class='input-item'>"+data.main.center_name+"</div></div><div class='form-item'><div class='input-label'>项目编号/名称</div><div class='input-item'>"+data.main.project_num+"/"+data.main.project_name+"</div></div><div class='form-item'><div class='input-label'>合同金额</div><div class='input-item'>"+data.main.contract_money+"</div></div><div class='form-item'><div class='input-label'>合同日期</div><div class='input-item'>"+data.main.contract_date+"</div></div><div class='form-item'><div class='input-label'>合同附件</div><div class='input-item'>";
				if(data.main.file_url){
					html+=""+data.main.file_name+"<a href='"+data.main.file_url+"' target='_blank' data-toggle='tooltip' data-placement='right' title='下载' class='ml5 download'><i class='glyphicon glyphicon-download-alt'></i></a>";
				}
				html+="</div></div><div class='form-item'><div class='input-label'>添加人(日期)</div><div class='input-item'>"+data.main.add_user+"("+data.main.add_date.slice(0,10)+")</div></div><div class='form-sub-title'>款项阶段</div></div><div class='form-table-item'><table class='table stage_table'><tr class='form-table-header'><td>阶段</td><td>应收款金额</td><td>百分比</td><td>应收款日期</td><td>应开票金额</td><td>应开票日期</td><td>预警日期</td><td>催款日期</td></tr>";
				for(var i=0; i<data.stage.length; i++){
					html+= "<tr><td>└第"+data.stage[i].stage+"阶段</td><td>"+data.stage[i].stage_money+"</td><td>"+data.stage[i].bili+"</td><td>"+data.stage[i].stage_date+"</td><td>"+data.stage[i].ticket_money+"</td><td>"+data.stage[i].ticket_date+"</td><td>"+data.stage[i].warn_date+"</td><td>"+data.stage[i].press_date+"</td></tr>"
				}
				html+= "</table></div>";
				$('#xm-modal .modal-body').html(html);
			}
		})
	})
	$('.kp_btn').click(function(){
		$('#kp-modal').modal();
		var id = $(this).attr("bbbid");
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"id":id,"action":"three","type":"2"},
			url:"__APP__/Financial/project_funds_total_ajax",
			success:function(data){
				var html="<div class='form-table-item'><table class='table stage_table'><tr class='form-table-header'><td>合同金额</td><td>合同日期</td><td>款项阶段</td><td>该阶段应开票金额</td><td>该阶段已开票金额</td><td>本次开票金额</td><td>本次开票日期</td><td>发票编号</td><td>添加人(日期)</td></tr>";
				html+= "<tr><td rowspan='"+data.max+"'>"+data.contract_money+"</td><td rowspan='"+data.max+"'>"+data.contract_date+"</td>"
				for(var i=0; i<data.two.length; i++){
					html+= "<td rowspan='"+data.two[i].max2+"'>第"+data.two[i].stage+"阶段</td><td rowspan='"+data.two[i].max2+"'>"+(data.two[i].stage_money-0)+"</td><td rowspan='"+data.two[i].max2+"'>"+data.two[i].sum+"</td>";
					var pp = data.two[i]['three'];
					if(pp){
						for(var p in pp){
							html+= "<td>"+pp[p].money+"</td><td>"+pp[p].date+"</td><td>"+pp[p].invoice+"</td><td>"+pp[p].add_user+"("+pp[p].add_date.slice(0,10)+")</td></tr>";
							if(p<pp){
								html+= "<tr>";
							}
						}
					}else{
						html+= "<td></td><td></td><td></td><td></td></tr><tr>";
					}
				}
				html+= "</table></td>";
				$('#kp-modal .modal-header h4').html("["+data.project_num+"]"+data.project_name+"");
				$('#kp-modal .modal-body').html(html);
			}
		})
	})
	$('.sk_btn').click(function(){
		$('#sk-modal').modal();
		var id = $(this).attr("cccid");
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"id":id,"action":"three","type":"3"},
			url:"__APP__/Financial/project_funds_total_ajax",
			success:function(data){
				var html="<div class='form-table-item'><table class='table stage_table'><tr class='form-table-header'><td>合同金额</td><td>合同日期</td><td>款项阶段</td><td>发票编号</td><td>该发票编号开票金额</td><td>该发票编号已收款金额</td><td>本次收款金额</td><td>本次收款日期</td><td>添加人(日期)</td></tr>";
				html+= "<tr><td rowspan='"+data.max+"'>"+data.contract_money+"</td><td rowspan='"+data.max+"'>"+data.contract_date+"</td>"
				for(var i=0; i<data.two.length; i++){
					html+= "<td rowspan='"+data.two[i].max2+"'>第"+data.two[i].stage+"阶段</td>";
					var pp = data.two[i]['three'];
					if(pp){
						for(var p in pp){
							html+= "<td rowspan='"+pp[p].max3+"'>"+pp[p].invoice+"</td><td rowspan='"+pp[p].max3+"'>"+pp[p].money+"</td><td rowspan='"+pp[p].max3+"'>"+pp[p].ysk+"</td>";
							var tt = pp[p]['four'];
							if(tt){
								for(var t in tt){
									html+= "<td>"+tt[t].money+"</td><td>"+tt[t].date+"</td><td>"+tt[t].add_user+"("+tt[t].add_date.slice(0,10)+")</td></tr>";
									if(t<tt){
										html+= "<tr>";
									}
								}
							}else{
								html+= "<td></td><td></td><td></td></tr><tr>";
							}
						}
					}else{
						html+= "<td></td><td></td><td></td><td></td><td></td><td></td></tr><tr>";
					}
				}
				html+= "</table></td>";
				$('#sk-modal .modal-header h4').html("["+data.project_num+"]"+data.project_name+"");
				$('#sk-modal .modal-body').html(html);
			}
		})
	})
});
</script>
</body>
</html>